import { Component, OnInit } from '@angular/core';
import { ApiService } from '../../../../providers/ApiPro.service';
import { parts } from '../HuoRestmp.model';

@Component({
  selector: 'app-ResOilcard',
  templateUrl: './ResOilcard.component.html',
  styleUrls: ['./ResOilcard.component.scss']
})
export class ResOilcardComponent implements OnInit {
  public pageIndex = 1;
  public data = [];
  public _total = 0;
  public createTime:string = null;
  public deadLine:string = null;
  public parts: parts = new parts();
  optionOilCardStatus  = [
    { value: '1', label: '正常' },
    { value: '2', label: '停用' },
    { value: '3', label: '异常' },
  ];
  
  constructor(
    public apiService: ApiService
  ) { }

  ngOnInit() {
    this.loadAll();
  }

  loadAll(){
    if(!this.parts.carNo){
      delete this.parts.carNo;
    };

    if(this.deadLine){
      this.parts.deadLine = this.apiService.formatDateTime2(this.deadLine);
    }else{
      delete this.parts.deadLine;
    };

    if(this.createTime){
      this.parts.createTime = this.apiService.formatDateTime2(this.createTime);
    }else{
      delete this.parts.createTime;
    };

    if(!this.parts.driverName){
      delete this.parts.driverName;
    };

    if(!this.parts.oilCardStatus){
      delete this.parts.oilCardStatus;
    };
    console.log(this.parts);
    let url = "findoilcards";
    this.apiService.get(url,this.parts)
      .then(res =>{
        this._total = res.totalCount;
        this.data = res.result;
        console.log(res);
      })
  }
  
  resetIndex(e) {
        this.parts.setPage(e);
        this.loadAll();
  }
}

